package com.leetcode.LC;

public class LC134 {
    public int canCompleteCircuit(int[] gas, int[] cost) {

        int a = 0, b = 0, currentGas = 0, start = 0;
        for (int i = 0; i < gas.length; i++) {
            a += gas[i];
            b += cost[i];
        }
        if (b > a)
            return -1;
        for (int i = 0; i < gas.length; i++) {
            currentGas = currentGas - cost[i] + gas[i];
            if (currentGas < 0) {
                currentGas = 0;
                start = i + 1;
            }
        }
        return start;
    }

    public static void main(String[] args) {
        System.out.println(new LC134().canCompleteCircuit(new int[]{1, 2, 3, 4, 5}
                , new int[]{3, 4, 5, 1, 2}));
    }
}
